<template>
    <h1>添加资源</h1>
    <el-form :model="sourcedata" label-width="auto" style="max-width: 600px">
    <el-form-item label="资源名字">
      <el-input v-model="sourcedata.name" />
    </el-form-item>
    <el-form-item label="资源路由">
      <el-input v-model="sourcedata.url" />
    </el-form-item>
    <el-form-item label="资源路由">
      <el-select v-model="sourcedata.pid_id" placeholder="选择父级资源">
        <el-option :label="item.name" :value="item.id" v-for="item in urlData"/>
      </el-select>
    </el-form-item>
    </el-form>
    <el-button type="primary" @click="submit">提交</el-button>


</template>




<script setup>
import { ref,onMounted } from 'vue'
import axios from 'axios';
import http from '../http';



const sourcedata = ref({
    "pid_id":"",
    'url':"",
    'name':'',

})



const urlData = ref([
    {
        "id": 0,
        "name": "父级资源",
    },
])
  
  
const getsourcedata = () => {
      axios.get('http://127.0.0.1:8000/rbac/psource/')
      .then((res) => {
          res.data.forEach((item) => {
              urlData.value.push(item)
          })
      })
  
  }
  
  
onMounted(() => {
      getsourcedata()
  })



const submit = () => {
    axios.post('http://127.0.0.1:8000/rbac/csource/',sourcedata.value)
      .then((res) => {
          console.log(res)
      })
}
   


</script>



<style scoped>



</style>